<?php

namespace App\Service\Index;

use App\Constants\ErrorCode;
use App\Helpers\AliyunUtil;
use App\Model\UserProfile;
use App\Model\UserRankDay;
use App\Model\UserRankMon;
use App\Model\UserRankTotal;
use App\Service\BaseService;

/**
 * 首页-魅力排行榜
 */
class RankService extends BaseService
{
    public function handle()
    {
        //rank_type - 排行榜类型
        $rankType = $this->request->input('rank_type', 1);
        $statType = $this->request->input('stat_type', 'day');
        $ret['list'] = $this->packData($rankType, $statType);
        return $ret;
    }

    /**
     * 封装数据
     */
    function packData($rankType, $statType)
    {
        $list = $data = [];
        switch ($statType) {
            case 'day':
                $list = UserRankDay::getList($rankType);
                break;
            case 'month':
                $list = UserRankMon::getList($rankType);
                break;
            case 'total':
                $list = UserRankTotal::getList($rankType);
                break;
        }
        array_walk($list, function ($rankItem) use (&$data, $rankType) {
            $item = UserRankDay::buildItem($rankItem, $rankType);
            if (!$item || $item['user_status'] != 0) return false;
            array_push($data, $item);
        });
        return $data;
    }
}
